<template>
  <div class="ele-body ele-body-card">
<!--        <div @click="cc">点击刷新</div>-->
    <!--    用户信息-->
    <profile-card />
    <!--    爆客码等数据详情-->
    <preview></preview>
    <!--    <statistics-card />-->
    <link-route></link-route>
    <!--    <link-card ref="linkCard" />-->
    <!--    图表-->
    <sale-card />

  </div>
</template>


<script>
  import { listRoleMenus, updateRoleMenus } from '@/api/system/role';
  import ProfileCard from './components/profile-card.vue';
  import LinkCard from './components/link-card.vue';
  import StatisticsCard from './components/statistics-card.vue';
  import SaleCard from './components/sale-card.vue';
  import preview from './components/dataPreview.vue';
  import linkRoute from './components/link-route.vue';
  import {removeUsers} from "@/api/equipmentManagement";
  import store from "@/store";
  import {getMenuRoutes} from "@/router/routes";
  import router from "@/router";
  export default {
    inject:['reload'],  //注入依赖
    name: 'AgencyDashboardMonitor',
    components: {
      ProfileCard,
      LinkCard,
      StatisticsCard,
      SaleCard,
      preview,
      linkRoute
    },
    computed: {
      // 是否开启响应式布局
      styleResponsive() {
        return this.$store.state.theme.styleResponsive;
      }
    },
    created(){
      console.log("reload11111111111")
      this.routers()
      // this.cc()
    },
    // 角色权限控制—— cookid和“代员工发布到D音” 展示
    /*created(){
      let info = localStorage.getItem('indexData') ? JSON.parse(localStorage.getItem('indexData')) : {};
      listRoleMenus({roleId: 16})  // 商家端id，如果总端的菜单管理‘商家端’被删除，则需要重新赋值
        .then((data) => {
          let cookieInfo={}   //D音cookie发布
          let userInfo={}   //用户库
          let empolyeesInfo={}   //D音代员工发布
          console.log("data",data)
          for(let i=0;i<data.length;i++){
            if(data[i].path=='/matrixManage/releaseManage/tiktok'){
              cookieInfo=data[i]
              data[i].checked=true
            }
            if(data[i].path=='/matrixManage/accountManage/userLibrary'){
              userInfo=data[i]
              data[i].checked=true
            }
            if(data[i].path=='/matrixManage/releaseManage/tiktokEmployees'){
              empolyeesInfo=data[i]
              data[i].checked=true
            }
          }
          console.log("data2222222222",data)

          console.log("cookieInfo,userInfo,empolyeesInfo",cookieInfo,userInfo,empolyeesInfo)

          let list=[]
          var arrNew=[];
          list = data.filter(item=> {
            return item.checked
          })
          console.log("list2222222",list)

          // 1.抖音h5 2.抖音无痕（cookie）_toCookieReleased 3.抖音代员工_toBeReleased 4.快手、
          if(info && info.toCookieReleased==1){
            //  如果是cookie，用户库和cookie发布存在，代用户发布则不存在
            list.forEach((value,index,array)=>{
              if(value.path == empolyeesInfo.path){
                array.splice(index,1)
              }
            })
            this.updateRole(list)
            console.log("list33333333",list)

          }
          if(info && info.toBeReleased==1){
            list.forEach((value,index,array)=>{
              if(value.path !=cookieInfo.path && value.path != userInfo.path){
                arrNew.push(value);
              }})
            this.updateRole(arrNew)
            console.log("newArrlis4444444444",arrNew)
          }
          if(!info || info.toCookieReleased!=1&&info.toBeReleased!=1){
            list.forEach((value,index,array)=>{
              if(value.path !=empolyeesInfo.path && value.path !=cookieInfo.path && value.path != userInfo.path){
                arrNew.push(value);
              }})
            this.updateRole(arrNew)
            console.log("newArrs55555555555",arrNew)
          }
        })
        .catch((e) => {
          this.$message.error(e.message);
        });
    },*/
    methods: {
      // 刷新侧边栏
      routers(){
        console.log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
        store.dispatch('user/fetchUserInfo')
          .then(({ menus, homePath }) => {
            console.log("成功---------------menus",menus)
            if (menus) {
              // router.addRoute(getMenuRoutes(menus, homePath));
              /*修改start*/
              getMenuRoutes(menus, homePath).forEach((r)=>{
                router.addRoute(r)
              })
              /*修改end*/
              // next({ ...to, replace: true });
            }
          })
          .catch((e) => {
            console.error(e);
            console.log("进入刷新失败catch-----------------")
            // console.log("menus222222",menus)
            // next();
          });
      },
      cc(){
        // this.$router.push({path:'/blankPage'})
        // this.reload()
      },
      /* 修改角色权限 */
      updateRole(list) {
        updateRoleMenus({roleId: 16, ids: list.map((d) => d.menuId)})
          // removeUsers({ids: list.map((d) => d.menuId)})
          .then((msg) => {
            console.log("修改角色权限=======",msg)
          })
          .catch((e) => {
            this.$message.error(e.message);
          });
      },
    }
  };
</script>
